﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER TR_Device_DeleteChildren
   ON dbo.Device 
   AFTER delete
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	if (select count(*) from deleted) > 0 
	begin
		delete from device
		where parentdeviceid in (
			select id
			from deleted
		);
	end
END
